package lambda.apple.v6;

import java.util.ArrayList;
import java.util.List;

public class App {

	public static void main(String[] args) {
		List<Apple> list = getApple();
		list = filterApples(list, new ApplePredicate() {
			@Override
			public boolean filter(Apple apple) {
				return apple.getColor().equals("green");
			}
		});
		list.forEach(System.out::println);
	}

	public static List<Apple> filterApples(List<Apple> inventory, ApplePredicate applePredicate) {
		List<Apple> result = new ArrayList<>();
		for (Apple apple : inventory) {
			if (applePredicate.filter(apple)) {
				result.add(apple);
			}
		}
		return result;
	}

	private static List<Apple> getApple() {
		List<Apple> list = new ArrayList<Apple>();
		list.add(new Apple("red", 100));
		list.add(new Apple("red", 200));
		list.add(new Apple("green", 100));
		list.add(new Apple("green", 200));
		return list;
	}

}